import { ADD, ADD_SUCCESS, ADD_FAIL, SET_TEMPLATE, SET_REMARK, SET_DATA } from '@/actions/templateEdit'

const initState = {
  id: null,
  template: '',
  remark: '',
  addButtonLoading: false
}

const templateEditReducer = (state = initState, action) => {
  switch (action.type) {
    case ADD:
      return { ...state, addButtonLoading: true }
      break;

    case ADD_SUCCESS:
      return { ...state, addButtonLoading: false, template: '', remark: '' }
      break

    case ADD_FAIL:
      return { ...state, addButtonLoading: false, template: '', remark: '' }
      break;

    case SET_TEMPLATE:
      return { ...state, template: action.template }
      break;

    case SET_REMARK:
      return { ...state, remark: action.remark }
      break;

    case SET_DATA:
      const { template, remark, id } = action.data
      return { ...state, template, remark, id }
      break;
  
    default:
      return state
      break;
  }
}

export default templateEditReducer